package ru.acme.lab11.service.bank;

import ru.acme.lab11.domain.bank.Bank;
import ru.acme.lab11.domain.bank.ImmutableBank;
import ru.acme.lab11.domain.client.Client;
import ru.acme.lab11.domain.client.ImmutableClient;
import ru.acme.lab11.exceptions.ClientExistsException;
import ru.acme.lab11.exceptions.NotEnoughFundsException;

public class BankService {
	
	public static void addClient(Bank bank, Client client) throws ClientExistsException {
		bank.addClient(client);
	}
	
	public static void modifyBank(Bank bank) throws NotEnoughFundsException {
		for (Client client : bank.getClients()) {
			if (Math.random() > 0.5) {
				client.getAccount().deposit((int)(100 * Math.random()));
			} else {
				client.getAccount().withdraw((int)(100 * Math.random()));
			}
		}		
	}

	public static void printBalances(ImmutableBank bank) {
		for (ImmutableClient client : bank.getImmutableClients()) {
			System.out.print(client.getImmutableAccount().getBalance() + " ");
		}
		System.out.println();
	}

	public static void printMaximumAmountsToWithdraw(ImmutableBank bank) {
		for (ImmutableClient client : bank.getImmutableClients()) {
			System.out.print(client.getImmutableAccount().maximumAmountToWihdraw() + " ");
		}
		System.out.println();
	}

}
